#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
快速获取管理员登录验证码
"""

import os
import sys
import django

# 设置Django环境
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'TradingPlatform_Server.settings')
django.setup()

from Server.sms_service import SMSService, send_login_code

def get_admin_code():
    """获取管理员登录验证码"""
    admin_phone = '13800138000'
    
    print("\n" + "="*60)
    print("获取管理员登录验证码")
    print("="*60)
    print("")
    
    # 发送验证码
    success, message, code = send_login_code(admin_phone)
    
    if success:
        print("[成功] 验证码已生成！")
        print("")
        print("  手机号: %s" % admin_phone)
        print("  验证码: %s" % code)
        print("  有效期: 5分钟")
        print("")
        
        # 验证缓存
        cached = SMSService.get_code_for_debug(admin_phone, 'login')
        print("[验证] 缓存中的验证码: %s" % cached)
        print("[验证] 验证码匹配: %s" % (str(cached) == str(code)))
        print("")
        
        print("="*60)
        print("请使用此验证码登录：%s" % code)
        print("="*60)
        print("")
    else:
        print("[失败] %s" % message)
        print("")

if __name__ == '__main__':
    try:
        get_admin_code()
    except Exception as e:
        print("\n[错误] %s" % str(e))
        import traceback
        traceback.print_exc()

